package com.joker.aigc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joker.aigc.domain.entity.R;
import com.joker.aigc.domain.dto.UserQueryCriteria;
import com.joker.aigc.domain.vo.UserVo;
import com.joker.aigc.service.UserService;

import com.joker.aigc.utils.RequestHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/api/1.0/user")
@Tag(name = "user", description = "用户相关接口")
public class UserController {


    private final UserService userService;

    /**
     * 根据条件查询用户信息
     *
     * @param criteria
     * @return
     */
    @Operation(summary = "批量获取用户信息", description = "批量获取用户信息，用于页面展示")
    @PostMapping("/list")
    public R<Page<UserVo>> queryAll(@RequestBody UserQueryCriteria criteria) {
        Long uid = RequestHolder.get().getUid();
        log.info("批量获取用户信息-->uid:{},query:{}", uid, criteria);
        return R.ok(userService.queryAll(criteria));
    }

    @Operation(summary = "根据id获取用户信息", description = "查询用户信息，用于个人页面展示")
    @GetMapping
    public R<UserVo> queryById() {
        Long uid = RequestHolder.get().getUid();
        log.info("UserController-->uid:{}", uid);
        return R.ok(userService.queryById(uid));
    }

    @PostMapping
    public R<Page<UserVo>> add(@RequestBody UserQueryCriteria criteria) {
        return R.ok(userService.queryAll(criteria));
    }

    @DeleteMapping
    public R<Page<UserVo>> update(@RequestBody UserQueryCriteria criteria) {
        return R.ok(userService.queryAll(criteria));
    }

    // 删除用户信息
    @PutMapping
    public R<Page<UserVo>> delete() {
        return R.ok(null);
    }

}
